<?php defined('BASEPATH') || exit('No direct script access allowed');

/**
 * Common controller
 */
class Common extends REST_Controller
{
    function __construct()
    {
        // Construct the parent class
        parent::__construct('rest_noauth');
    }

    /**
     * 七牛上传token
     * @return json
     */
    public function qiniuUploadToken_get() {
        require APPPATH.'third_party/Qiniu-7.0.7/autoload.php';

        // parent::showProfiler(false);
        $this->output->enable_profiler(false);

        // 个人测试账号
        // $accessKey = 'sSRSrUD-G4Jvj6DUkoH_KwjSZwj39wCYL7nK7ZPx';
        // $secretKey = 'eStkT02p6sR5m2SYZSPBfn2cGmqvyB97ohw28AgI';
        // 公司账号
        $accessKey = config_item('qiniu.access_key');
        $secretKey = config_item('qiniu.secret_key');

        // 构建鉴权对象
        $auth = new Qiniu\Auth($accessKey, $secretKey);

        // 要上传的空间
        $bucket = config_item('qiniu.bucket');

        // 生成上传 Token
        $token = $auth->uploadToken($bucket);

        $this->response(['uptoken'=>$token]);
    }

}